﻿<!DOCTYPE html>
<!--安全分委会组织架构-->
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
        <script src="/static/js/common.js"></script>

</head>

<body>
    <div id="app" v-cloak class="popupW100">
        <el-form :model="Form" status-icon :rules="rules" ref="ruleForm" label-width="100px" size="mini"
            label-position="right">
            <el-row>
                <el-col :span="11">
                    <div class="elst-select-mini">
                        <el-form-item>
                            <el-input size="mini">
                                <template slot="prepend">
                                    {{OrganizationalStructureSafety.Name+mark.m}}
                                </template>
                                <treeselect v-model="Form.name"
                                            :options="name"
                                            :flat="true"
                                            :show-count="true"
                                            slot="suffix"
                                            style="line-height: 28px;"
                                            placeholder="请选择" />
                            </el-input>
                        </el-form-item>
                    </div>
                </el-col>


                <el-col :span="11" offset="2">
                    <el-col>
                        <div class="elst-select-mini">
                            <el-form-item>
                                <el-input size="mini">
                                    <template slot="prepend">
                                        {{OrganizationalStructureSafety.Department+mark.m}}
                                    </template>
                                    <treeselect v-model="Form.department"
                                                :options="department"
                                                :flat="true"
                                                :show-count="true"
                                                slot="suffix"
                                                style="line-height: 28px;"
                                                placeholder="请选择" />
                                </el-input>
                            </el-form-item>
                        </div>
                    </el-col>
                </el-col>
                <el-col :span="11">
                    <el-col>
                        <div class="elst-select-mini">
                            <el-form-item prop="phoneNumber">
                                <el-input type="text" v-model="Form.phoneNumber" autocomplete="off" size="mini">
                                    <template slot="prepend">
                                        {{OrganizationalStructureSafety.PhoneNumber+mark.m}}
                                    </template>
                                </el-input>
                                <!--<span class="iputLineMust" v-if="Form.PhoneNumber.length<=0">
                         必填项添加
                        <img src="/static/images/exclamation.png" alt="">
                    </span>-->
                            </el-form-item>
                        </div>
                    </el-col>
                </el-col>
                <el-col :span="11" offset="2">
                    <el-col>
                        <div class="elst-select-mini">
                            <el-form-item prop="extensionNumber">
                                <el-input type="text" v-model="Form.extensionNumber" autocomplete="off" size="mini">
                                    <template slot="prepend">
                                        {{OrganizationalStructureSafety.ExtensionNumber+mark.m}}
                                    </template>
                                </el-input>
                                <!--<span class="iputLineMust" v-if="Form.ExtensionNumber.length<=0">
                         必填项添加
                        <img src="/static/images/exclamation.png" alt="">
                    </span>-->
                            </el-form-item>
                        </div>
                    </el-col>
                </el-col>
                <el-col>
                    <div class="elst-select-mini">
                        <el-form-item>
                            <el-input size="mini">
                                <template slot="prepend">
                                    {{OrganizationalStructureSafety.FrameWork+mark.m}}
                                </template>
                                <treeselect v-model="Form.zbSafetyFrameWorkId"
                                            :options="dafetyFrameWork"
                                            :flat="true"
                                            :show-count="true"
                                            slot="suffix"
                                            style="line-height: 28px;"
                                            placeholder="请选择" />
                            </el-input>
                        </el-form-item>
                    </div>
                </el-col>
            </el-row>
            <el-row type="flex" justify="end">
                <el-form-item>
                    <el-button type="primary" @click="onSubmitForm('ruleForm')">{{col.btnSave}}</el-button>
                    <!--<el-button type="primary" @click="onSubmitForm('ruleForm')">{{col.btnCommit}}</el-button>-->
                    <el-button type="primary" @click="parent.ListItem.dialogVisible=false">{{col.btnBack}}</el-button>
                </el-form-item>
            </el-row>
        </el-form>
        <el-dialog title="安全分委会组织架构-人员添加" fullscreen="true"  :visible.sync="ListItem.dialogVisible" @close='closeDialog' width="80%"
            height="80%" top="10vh">
            <iframe ref="iframe" :src="ListItem.InputUrl" style="height:95%;width:100%" frameborder="0"></iframe>
        </el-dialog>
    </div>
    <script type="text/javascript">

        var app = new Vue({
            el: '#app',
            data: {
                //父业传参
                ListItem: ListItem,

                id: '',
                //业务表单内容
                formInline: {
                    model: { name: '', department: null, loginName: '', SysUserInfor: { sex: '', WorkCompany: null } },
                    offset: 0,
                    limit: 10
                },
                Form: {
                    id: guidEmpty,
                    name: null,
                    department: null,
                    zbsafetyFrameWorkId: null,
                    PhoneNumber: '',
                    ExtensionNumber: '',
                },
                name: [],
                department: [],
                dafetyFrameWork: [],
                PhoneNumber: [],
                ExtensionNumber: [],
                //表单验证
                rules: {

                }
            },
            methods: {
                //解決edge下select bug
                visibleChange: function (isVisible) {
                    visibleChange(isVisible)
                },
                //提交数据
                onSubmitForm: function (formName) {
                    var mythis = this;
                    this.$refs[formName].validate(function (valid) {
                        //验证通过
                        if (valid) {
                            onSubmitForm(this, '/api/ZB_SafetyUser/Save', mythis.Form);
                        } else {
                            //验证失败
                            return false;
                        }
                    });

                },
                getData: function () {

                    getData(this, '/api/ZB_SafetyUser/get?id=' + this.id);

                },
                addName: function (val, id) { DialogShow(this, val, "OrganizationalStructureSafetyInputNameAdd.html", id); },
                //初始化部门下拉树
                GetDepartment: function () {
                    var mythis = this;
                    myAjax("post", this, '/api/SysDepartment/GetList', { model: { Name: '', Code: '', CreateFactory: '' }, offset: 0, limit: 999 }, function (response) {
                        mythis.department = menuHelperX(response.data.pageData, guidEmpty)
                    }, false);
                },
                //人员
                GetUserList: function () {

                    var mythis = this;
                    myAjax("post", mythis, '/api/ZB_SafetyUser/GetUserList', { model: { loginName: '', SysUserInfor: { sex: '', WorkCompany: null }}, offset: 0, limit: 100 }, function (response) {
                        console.log(response);
                        //response.data.forEach(function (v) {
                        //    v.label = v.name;
                        //})
                       // mythis.Name = response.data;
                        mythis.name = menuHelperX(response.data.pageData, guidEmpty)
                        console.log('AA', mythis.dafetyFrameWork)
                        //   mythis.Form.OrganizationalStructureMaintenance = response.data;
                    });
                },


                //总部_安全分委会架构
                GetSafetyFrameWork: function () {
                    var mythis = this;
                    //myAjax("post", this, '/api/ZB_SafetyFrameWork/GetList', { model: { Name: '', pid: '' }, }, function (response) {
                    //    mythis.dafetyFrameWork = menuHelperX(response.data.pageData, guidEmpty)
                    //}, false);

                    var mythis = this;
                    myAjax("post", mythis, '/api/ZB_SafetyFrameWork/GetList', { model: {}, offset: 0, limit: 100 }, function (response) {
                        console.log(response);
                        //response.data.forEach(function (v) {
                        //    v.label = v.name;
                        //})
                        mythis.dafetyFrameWork = MenuHelper(response.data, guidEmpty);
                        console.log('AA', mythis.dafetyFrameWork)
                        //   mythis.Form.OrganizationalStructureMaintenance = response.data;
                    });
                },

            },
            mounted: function () {
                //this.PhoneNumber = getDicData('03');
                //this.Name = getDicData('21');
                //this.Department = getDicData('14');
                this.id = getUrlParam("id");
                this.getData();
                this.Department = this.GetDepartment();
                this.name = this.GetUserList();
                this.dafetyFrameWork = this.GetSafetyFrameWork();
                
            }
        });
        //下拉树数据格式化
        function menuHelperX(list, pid) {
            var result = [];
            if (list.length <= 0)
                return list;
            list.forEach(function (v, i) {
                var temp = {};
                for (var key in v) {
                    temp[key] = v[key];
                }
                temp.label = v.name;
                temp.parentId = temp.parentId ? temp.parentId : guidEmpty;
                var obj;
                if (temp.parentId == pid) {
                    obj = temp;
                    var nextObj = menuHelperX(list, temp.id);
                    if (nextObj.length > 0) {
                        obj.children = nextObj;
                    }
                }
                if (obj)
                    result.push(obj)
            })
            return result;
        }
       
        function MenuHelper(list, pid) {
            var result = [];
            list.forEach(function (v, i) {
                if (!v.pid) v.pid = guidEmpty;
                if (v.pid == pid) {
                    var obj = {};
                    obj.id = v.id + '';
                    obj.label = v.name + '';
                    obj.icon = 'tree-item';
                    var nextObj = MenuHelper(list, v.id);
                    if (nextObj.length > 0) {
                        obj.children = nextObj;
                        obj.icon = 'tree-open';
                    }
                }
                if (obj)
                    result.push(obj)
            })
            return result;
        }
    </script>
</body>

</html>